'use strict';
const db = uniCloud.database();
let response = function(code, data, msg) {
	return {
		code: code,
		data: data,
		msg: msg || '成功'
	}
}

exports.main = async (event, context) => {
	if (!event.collectionName)
		return response(60000, undefined, '参数错误')
	let collection = await db.collection(event.collectionName);
	if (!db)
		return response(60000, undefined, '数据库不存在')
	var docData;
	if (event.docId) {
		if (event.docId != event.collectionName) {
			return response(10000, await collection.doc(event.docId).remove())
		} else {
			let res = await collection.get() //删除当前集合所有数据
			res.data.map(async (item) => {
				return await collection.doc(item.id).remove()
			})
		}
	}
};
